<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>动态弹幕效果</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            overflow: hidden;
            background-color: #000;
            color: #fff;
            position: relative;
        }
        .danmu-container {
            position: relative;
            width: 100%;
            height: 100vh;
        }
        .danmu {
            position: absolute;
            white-space: nowrap;
            padding: 5px 10px;
            background-color: rgba(0, 0, 0, 0.5);
            border-radius: 5px;
            font-size: 16px;
            animation: slide 10s linear infinite;
        }
        @keyframes slide {
            0% { transform: translateX(100%); }
            100% { transform: translateX(-100%); }
        }
        .speed-slider {
            position: absolute;
            bottom: 10px;
            left: 50%;
            transform: translateX(-50%);
            width: 80%;
        }
        .input-container {
            position: absolute;
            bottom: 60px;
            left: 50%;
            transform: translateX(-50%);
            width: 80%;
            display: flex;
            gap: 10px;
        }
        .input-container input[type="text"] {
            flex: 1;
            padding: 10px;
            border: 2px solid #fff;
            border-radius: 5px;
            background-color: rgba(255, 255, 255, 0.2);
            color: #fff;
        }
        .input-container button {
            padding: 10px 20px;
            border: 2px solid #fff;
            border-radius: 5px;
            background-color: rgba(255, 255, 255, 0.2);
            color: #fff;
            cursor: pointer;
        }
        .input-container button:hover {
            background-color: rgba(255, 255, 255, 0.4);
        }
    </style>
</head>
<body>
    <div class="danmu-container">
        <div class="danmu" style="top: 10px;">欢迎来到直播间！</div>
        <div class="danmu" style="top: 30px;">大家好，我是主播</div>
        <div class="danmu" style="top: 70px;">感谢大家的支持！</div>
        <div class="danmu" style="top: 90px;">记得点赞和关注哦！</div>
    </div>
    <div class="input-container">
        <input type="text" id="danmu-input" placeholder="输入弹幕内容">
        <button id="send-danmu">发送</button>
    </div>
    <div class="speed-slider">
        <label for="speed">弹幕速度：</label>
        <input type="range" id="speed" name="speed" min="1" max="10" value="5">
    </div>

    <script>
        const speedSlider = document.getElementById('speed');
        const danmuContainer = document.querySelector('.danmu-container');
        const danmuInput = document.getElementById('danmu-input');
        const sendDanmuButton = document.getElementById('send-danmu');

        // 动态调整弹幕速度
        speedSlider.addEventListener('input', function() {
            const speed = speedSlider.value;
            const danmus = document.querySelectorAll('.danmu');
            danmus.forEach(danmu => {
                danmu.style.animationDuration = `${10 / speed}s`;
            });
        });

        // 发送弹幕
        sendDanmuButton.addEventListener('click', function() {
            const danmuText = danmuInput.value.trim();
            if (danmuText === '') return;

            const newDanmu = document.createElement('div');
            newDanmu.classList.add('danmu');
            newDanmu.style.top = `${Math.random() * 80 + 10}px`; // 随机生成垂直位置
            newDanmu.textContent = danmuText;

            danmuContainer.appendChild(newDanmu);

            // 清空输入框
            danmuInput.value = '';
        });

        // 按下回车键发送弹幕
        danmuInput.addEventListener('keypress', function(event) {
            if (event.key === 'Enter') {
                sendDanmuButton.click();
            }
        });
    </script>
</body>
</html>